package com.breakfast.fun.adapter.home;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.breakfast.fun.Constant;
import com.breakfast.fun.MainActivity;
import com.breakfast.fun.base.BaseListAdapter;
import com.breakfast.fun.data.entity.home.CityData;
import com.breakfast.fun.R;
import com.breakfast.fun.ui.home.HomeFragment;
import com.breakfast.fun.ui.other.city.CityActivity;
import com.breakfast.fun.util.SharedUtil;
import com.google.gson.Gson;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 城市选择适配器
 * Created by hp on 2016/8/22.
 */
public class CityAdapter extends BaseListAdapter<CityData> {


    public CityAdapter(Context context, List<CityData> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_city, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvCityItem.setText(getItem(position).getCityName());
        if (getItem(position).getState() == 2) {
            holder.tvCityNotOpen.setVisibility(View.VISIBLE);
        } else {
            holder.tvCityNotOpen.setVisibility(View.GONE);
        }

        return convertView;
    }


    static class ViewHolder {
        @Bind(R.id.tv_city_item)
        TextView tvCityItem;
        @Bind(R.id.tv_city_not_open)
        TextView tvCityNotOpen;
        @Bind(R.id.ll_item_city)
        LinearLayout llItemCity;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
